﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebClient
{
    public partial class Client : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                loadNews();
                this.AutoUSD();
            }
            if (Session["users"] == null)
            {
                this.dangnhap1.Visible = true;
                LoginView1.Visible = false;
                this.canhan1.Visible = false;
                this.admin.Visible = false;
            }
            else
            {
                this.dangnhap1.Visible = false;
                LoginView1.Visible = true;
                this.canhan1.Visible = true;
                DTO.Users item = (DTO.Users)Session["users"];
                if (item.groupID != 4)// neu users la thuoc phan quan tri thi hien lick de cho toi trang quan tri
                    this.admin.Visible = true;
                else
                    this.admin.Visible = false;//neu la khach thi ko hien thi link cua trang quan tri
            }
        }

        private void loadNews(){
            WebData db = new WebData();
            this.rptTopNews.DataSource = db.GetAllNews();
            this.rptTopNews.DataBind();
        }

        private void AutoUSD() {
            WebData db = new WebData();
            DTO.Foreigncurrency forcur = new DTO.Foreigncurrency();
            String s = lblUSD.Text.Trim().Replace(",", "").Replace(".", "");
            s = s == "" ? "0" : s;
            forcur.rate = Convert.ToDecimal(s);
            forcur.updateDate = DateTime.Now;
            forcur.isActive = 1;
            forcur.id = 1;
            db.OnSubmitForeigncurrency(forcur, 0);
        }
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            
        }
    }
}